package com.studerb.tests.service;

import java.util.List;

import org.junit.*;
import static org.junit.Assert.*;

import com.studerb.model.NewsGroup;
import com.studerb.model.Server;
import com.studerb.service.*;
import com.studerb.service.interfaces.INewsGroupService;

import javax.swing.JOptionPane;

public class TestHeaderService {

	protected HeaderService headerService;
	protected INewsGroupService groupService;
	protected SettingsService settingsService;
	protected ServerService serverService;
	
	@BeforeClass
	public static void beforeClass(){
		JOptionPane.showMessageDialog(null, 
				"Make sure network is on and Main has been run to load database with servers and groups");
	}
	
	@Test
	public void testDownloadHeaders() throws Exception{
//		NewsGroup smallNewsGroup = getSmallGroup();
	}

	//public void downloadNewHeaders(NewsGroup group) throws ServiceException
	@Test
	public void testDownloadNewHeaders() {
		fail("Not yet implemented");
	}

	//public void downloadAllHeaders(NewsGroup group) throws ServiceException
	@Test
	public void testDownloadAllHeaders() {
		fail("Not implemented");
	}
	
	private NewsGroup getSmallGroup() throws Exception {
		List<NewsGroup> newsGroups = groupService.getNewsGroups();
		assertNotNull(newsGroups);
		assertTrue(newsGroups.size() > 100);
		
		Server server = serverService.getMasterServer();
		assertNotNull(server);
		//get a newsgroup with about 150 posts
		for (NewsGroup ng : newsGroups) {
			if (ng.getPostsCount() > 100 && ng.getPostsCount() < 200) {
				return ng;
			}
		}
		throw new Exception("Could not find small newsgroup (100 - 200 headers)");
	}
	
}
